<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			const arr = [1, 4, 13, 5, 12]
			// 如果函数体只有一句代码,并且代码的执行结果就是函数的返回值,函数体大括号可以省略			
			//console.log(arr.sort((a, b)=>{return a - b}));
			console.log(arr.sort((a, b) => a - b));

			const arr1 = (n1, n2) => n1 + n2;
			console.log(arr1(1, 2)); //3
			
			// 如果形参只有一个,小括号也是可以省略			
			const arr2 = a => a;
			console.log(arr2(2)); //2
			
			// 箭头函数不绑定this,箭头函数没有自己的this关键字,
			// 如果在箭头函数中使用this,this关键字指向箭头函数中定义的this
			function fn() {
				console.log(this); //Object
				return () => {
					console.log(this); //Object
				}
			}
			const obj = {
				name: 'andy'
			};
			const resFn = fn.call(obj);
			resFn();
			
			// 剩余参数
			//const sum = (first,...args) => {//50
			const sum = (...args) => {
				let total = 0;
				args.forEach(item => total += item);
				return total;
			}
			console.log(sum(10, 20, 30)); //60
			
			// 剩余参数和解构配合使用	
			let students = ['zhangsan', 'lisi', 'me'];
			let [s1, ...s2] = students;
			console.log(s1); //zhangsan
			console.log(s2); //['lisi', 'me']
		</script>
	</body>
</html>
